#include <stdio.h>
#include "lcv/dip.h"
#include "lcv/bmp.h"
#include "lcv/cam.h"
#include "config.h"

void test_dip()
{
	char filename[sizeof(FOLDER_PREFIX) + 50];	
	
	printf("capturing frame (should have been tested before)... ");
	fflush(stdout);
	lcv_picture picture = lcv_capture_frame(FULLSIZE_INPUT_IMAGE);
	sprintf(filename, "%sdip_capture_frame.bmp", FOLDER_PREFIX);
	lcv_write_bmp(picture, filename);
	printf("ok\n");
	
	printf("writing invert bmp... ");
	fflush(stdout);
	lcv_picture p_invert = lcv_invert(&picture);
	sprintf(filename, "%sdip_inverted.bmp", FOLDER_PREFIX);
	lcv_write_bmp(p_invert, filename);
	printf("ok\n");
	lcv_free_picture(&p_invert);
	
	printf("writing reversed bmp... ");
	fflush(stdout);
	lcv_picture p_reverse = lcv_reverse(&picture);
	sprintf(filename, "%sdip_reversed.bmp", FOLDER_PREFIX);
	lcv_write_bmp(p_reverse, filename);
	printf("ok\n");
	lcv_free_picture(&p_reverse);
	
	printf("writing gray bmp... ");
	fflush(stdout);
	lcv_picture p_gray = lcv_rgb2gray(&picture);
	sprintf(filename, "%sdip_gray.bmp", FOLDER_PREFIX);
	lcv_write_bmp(p_gray, filename);
	printf("ok\n");
		
	printf("writing gray inverted bmp... ");
	fflush(stdout);
	lcv_picture p_gray_inv = lcv_invert(&p_gray);	
	sprintf(filename, "%sdip_gray_inverted.bmp", FOLDER_PREFIX);
	//lcv_write_bmp(p_gray_inv, filename);
	printf("ok\n");
	lcv_free_picture(&p_gray_inv);
	
	printf("writing gray reversed bmp... ");
	fflush(stdout);
	lcv_picture p_gray_rev = lcv_reverse(&p_gray);
	sprintf(filename, "%sdip_gray_reversed.bmp", FOLDER_PREFIX);
	//lcv_write_bmp(p_gray_rev, filename);
	printf("ok\n");
	lcv_free_picture(&p_gray_rev);
	
	printf("averange value of gray... %u\n", lcv_avg_value(&p_gray));
	//printf("averange value of inverted gray... %u\n", lcv_avg_value(&p_gray_inv));
	
	
	lcv_free_picture(&picture);	
	lcv_free_picture(&p_gray);
	
}
